/**
 * Created by John on 2016/7/8.
 */
function dispalayWords(cursor) {
    var words = cursor.forEach(function (word) {
        print(JSON.stringify(word, null, 2));
    });
}

var mongo = new Mongo("localhost");
var wordsDB = mongo.getDB("BeginningMongoDB");
wordsColl = wordsDB.getCollection("word_stats");

var cursor = wordsColl.find({first: 'p'});
print("Full Word:");
dispalayWords(cursor.limit(1));

cursor = wordsColl.find({first: 'p'}, {word: true});
print();
print("Only the word field:");
dispalayWords(cursor.limit(1));

cursor = wordsColl.find({first: 'p'}, {word: true, size: true, stats: true});
print();
print("Only the word, size and stats fields:");
dispalayWords(cursor.limit(1));

cursor = wordsColl.find({first: 'p'}, {charsets: false, stats: false});
print();
print("Excluding charsets and stats:");
dispalayWords(cursor.limit(1));